if (typeof UWA == "undefined") var UWA = {};

UWA.Class = Class;

UWA.Form = {
  getElements: function(form) {
    
    // commented code is bugged with IE7 (mootools issue)
    // return form.getElementsBySelector('input, textarea, select');
    
    var search = [];
    search.push( form.getElementsByTagName('input') );
    search.push( form.getElementsByTagName('textarea') );
    search.push( form.getElementsByTagName('select') );
    
    var results = [];
    for(var i = 0; i < search.length; i++) {
      for(var j = 0; j < search[i].length; j++) {
        results.push( search[i][j] );
      }
    }
    return results;
    
  }
}

UWA.Ajax = {
  Request: function(url, request) {
    if(request.method) request.method = request.method.toLowerCase();
    if(request.parameters) request.data = request.parameters;
    // if(request.postBody) request.data = request.postBody;
    if(request.requestHeaders) request.headers = request.requestHeaders;
    return new Ajax(url, request).request();
  },
  onCompleteXML: function(arg, callback, context) {
    if(typeof callback == "function") callback(arg[1])
  },
  onCompleteText: function(arg, callback, context) {
    if(typeof callback == "function") callback(arg[0])
  },
  onCompleteFeed: function(arg, callback, context) {
    var response = {responseText: arg[0], responseXML: arg[1]};
    var feed = UWA.Utils.parseFeed(response);
    if(typeof callback == "function") callback(feed)
  },
  onCompleteJson: function(arg, callback, context) {
    try {
      eval("var j = " + arg[0]);
      if(typeof callback == "function") callback(j, context);
    } catch(e) {
      UWA.log(e);
    }
  }
}

UWA.$element = function(el){
  if (el) {
    if (!el.isUwaExtended) {
      UWA.extend(el, UWA.Element);
      el.isUwaExtended = true;
    }
    return $(el);
  }
}

if (typeof UWA.Element == "undefined") UWA.Element = {};

// if (typeof UWA.Element.methods == "undefined") UWA.Element.methods = {};

UWA.extend(UWA.Element, {
  
  hasClassName: function(className) {
    return this.hasClass(className);
  },
  addClassName: function(className) {
    return this.addClass(className);
  },
  removeClassName: function(className) {
    return this.removeClass(className);
  },
  hide: function() {
   return this.setStyle('display', 'none');
  },
  show: function() {
    return this.setStyle('display', '');
  },
  toggle: function() {
    if(this.style.display == 'none') {
      this.style.display = '';
    } else {
      this.style.display = 'none';
    }
  },
  getDimensions: function() {
    // return Element.getDimensions(this); // from moocompat - to be integrated into UWA core
    var dimensions = this.getSize();
    return { 'width' : dimensions.size.x , 'height' : dimensions.size.y }
  }
  
} );